<h1>IT Department Primer</h1>
<b>Learning Symfony: Creating a Textinput module</b>
<br>
<br><a href="index.html">Back to Home</a>
<br>
<br><hr><b>Textinput</b>
<br>
<br>The biggest problem with manual encoding in a web program is that it's slow, especially if it's hosted in the internet. I came up with a way to speed things up. In the government, most data is written in Excel files. I've come up with a way to copy the data from the spreadsheet and paste it into a textarea, since it's way faster to write in a spreadsheet. Government employees are used to it. It doesn't make you wait for the page to load after you save each record. And a lot of the old data already exists in spreadsheet form.
<br>
<br>Textinput works by taking in all the data as a single very long string, taken from the Excel spreadsheet. The thing about pasting spreadsheet data, is that column breaks turn into TAB characters. Check out copying several cells from a spreadsheet and pasting it into Notepad or any text editor - you'll see what I mean. By using the PHP string function explode("\t",$inputstring), you can separate a single row into its component cells. Of course you'll have to cut the input string up into rows first, using "explode("\n",$inputstring)".
<br>
<br>//this will give you a 2 dimentional array containing the individual strings in each cell of the spreadsheet.
<br>$rows=explode("\n",$inputstring);
<br>$cells=array();
<br>foreach($rows as $row)
<br>&nbsp;&nbsp;&nbsp;&nbsp;$cells[]=explode("\t",$row);
<br>
<br>After that, you'll have to interpret the data, check it for errors, and save it as records in the database.
<br>
<br>To create a textinput module, create a normal module using "php symfony init-module frontend textinput" where textinput is the name of the module. 
<br>
<br>then paste this into the action file: 
<br><hr>
<br>//this will give you a 2 dimentional array containing the individual strings in each cell of the spreadsheet. It will also trim the contents of each cell, removing leading and trailing spaces. 
<br>&nbsp;&nbsp;private&nbsp;function&nbsp;parse($string)
<br>&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;$cells=array();
<br>&nbsp;&nbsp;&nbsp;&nbsp;$rows=explode("\n",$string);
<br>&nbsp;&nbsp;&nbsp;&nbsp;foreach($rows&nbsp;as&nbsp;$row)
<br>&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$rowarray=explode("\t",$row);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach($rowarray&nbsp;as&nbsp;$stringindex=>$string)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$rowarray[$stringindex]=trim($string);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$cells[]=$rowarray;
<br>&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;$cells;
<br>&nbsp;&nbsp;}
<br>&nbsp;&nbsp;
<br>&nbsp;&nbsp;public function executeInput(sfWebRequest $request)
<br>&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;//global variables:
<br>&nbsp;&nbsp;&nbsp;&nbsp;//input parameters
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->string=$request->getParameter('journal[text]');
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->title=$request->getParameter('journal[title]');
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->type=$request->getParameter('journal[type]');
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->respcentercode=$request->getParameter('journal_entry[resp_center_code]');
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->fund_id=$request->getParameter('journal[fund_id]');
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->author=$request->getParameter('journal[author]');
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->accountno=$request->getParameter('journal[accountno]');
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->preparedby1=$request->getParameter('journal[preparedby1]');
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->preparedby2=$request->getParameter('journal[preparedby2]');
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->certifiedby1=$request->getParameter('journal[certifiedby1]');
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->certifiedby2=$request->getParameter('journal[certifiedby2]');
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;//output strings 
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->messages=array();//success / ordinary message
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->errors=array();//something's wrong
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->warnings=array();//something might be wrong
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;//data variables
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->cells=array();&nbsp;&nbsp;&nbsp;&nbsp;//2 dimentional array containing spreadsheet cells
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->compileddata=array();&nbsp;//contains data separated into objects, but not objects yet.
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->items=array();//data objects
<br>&nbsp;&nbsp;&nbsp;&nbsp;//or you can use a textinput engine
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->tie=null;//use a textinput engine, for advanced data manipulation (see /lib/model/doctrine/textinputengine.class.php)<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;if(!$this->string)return;//if no data in textbox, don't do anything
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;//-----------------------input parameter validation
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;if(!$this->title)
<br>&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//this is how you send an error message to screen
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->errors[]="Journal&nbsp;Name&nbsp;Required";
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;
<br>&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;$fund=Doctrine::getTable('Fund')->find(array($this->fund_id));
<br>&nbsp;&nbsp;&nbsp;&nbsp;if(!$fund)
<br>&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->errors[]="Fund&nbsp;Required";
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;
<br>&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->journal=JournalTable::fetchByName($this->title,$fund,PeriodTable::getCurrentPeriod(),$this->type,$this->author,$this->accountno,$this->preparedby1,$this->preparedby2,$this->certifiedby1,$this->certifiedby2);
<br>&nbsp;&nbsp;&nbsp;&nbsp;if(!$this->journal){$this->errors[]="Error&nbsp;fetching&nbsp;journal";return;}
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;//-----------------------setup&nbsp;textinput&nbsp;engine
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->tie=new&nbsp;TextInputEngine($this->string,$this->journal,$this->respcentercode);
<br>&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;//if&nbsp;empty&nbsp;data&nbsp;or&nbsp;errors&nbsp;exist,&nbsp;quit
<br>&nbsp;&nbsp;&nbsp;&nbsp;if(!$this->tie&nbsp;or&nbsp;$this->tie->hasErrors())return;
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;//-------------------------generate-----------------------------
<br>&nbsp;&nbsp;&nbsp;&nbsp;if($request->getParameter('submit')=='Generate'&nbsp;and&nbsp;count($this->errors)==0)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->tie->generate();
<br>&nbsp;&nbsp;}
<br><hr>
<br>As you might notice, most of the processing is done by the textinput engine. This gives me a lot more power and flexibility. To create a textinput engine, create the file /lib/model/doctrine/TextInputEngine.class.php (feel free to change the name) and paste this into it:
<br>
<br><hr>
<?php
<br>class&nbsp;TextInputEngine
<br>{
<br>&nbsp;&nbsp;/*
<br>&nbsp;&nbsp;------------------------------------
<br>&nbsp;&nbsp;Usage: this goes into the action file
<br>&nbsp;&nbsp;&nbsp;&nbsp;//create the textinput engine object
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->tie=new&nbsp;TextInputEngine($this->string,$this->otherdata);
<br>&nbsp;&nbsp;&nbsp;&nbsp;//if errors exist, send them to screen and exit
<br>&nbsp;&nbsp;&nbsp;&nbsp;if(!$this->tie&nbsp;or&nbsp;$this->tie->hasErrors())return;
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;//fetch&nbsp;items to display on screen 
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->items=$this->tie->getItems();
<br>&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;//save to database if "generate" button was pressed, and if there are no errors
<br>&nbsp;&nbsp;&nbsp;&nbsp;if($request->getParameter('submit')=='Generate'&nbsp;and&nbsp;count($this->errors)==0)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->tie->generate();
<br>&nbsp;&nbsp;------------------------------------
<br>&nbsp;&nbsp;*/
<br>
<br>&nbsp;&nbsp;private&nbsp;$string="";
<br>&nbsp;&nbsp;private&nbsp;$fields=array();
<br>&nbsp;&nbsp;//customize&nbsp;this
<br>&nbsp;&nbsp;private&nbsp;$requiredfields=array('date','code');
<br>&nbsp;&nbsp;private&nbsp;$optionalfields=array('ref','checkno','payee','particulars','payeeparticulars','sundry','sundrydebit','sundrycredit','pr','dvno','obrno','pto');
<br>
<br>&nbsp;&nbsp;private&nbsp;$output=array();&nbsp;&nbsp;&nbsp;&nbsp;//this&nbsp;is&nbsp;the&nbsp;parsed&nbsp;data
<br>&nbsp;&nbsp;private&nbsp;$fieldcols=array();&nbsp;//this&nbsp;contains&nbsp;the&nbsp;column&nbsp;positions&nbsp;of&nbsp;each&nbsp;field
<br>
<br>&nbsp;&nbsp;private&nbsp;$items=array();&nbsp;&nbsp;&nbsp;//this&nbsp;are&nbsp;the&nbsp;documents
<br>&nbsp;&nbsp;private&nbsp;$errors=array();
<br>&nbsp;&nbsp;private&nbsp;$warnings=array();
<br>&nbsp;&nbsp;private&nbsp;$messages=array();
<br>
<br>&nbsp;&nbsp;//customize&nbsp;this
<br>&nbsp;&nbsp;//auxilliary&nbsp;data
<br>&nbsp;&nbsp;private&nbsp;$accountcodes=null;
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;getAccountCodes(){return&nbsp;$this->accountcodes;}
<br>
<br>&nbsp;&nbsp;private&nbsp;$respcentercode=null;
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;getRespCenterCode(){return&nbsp;$this->respcentercode;}
<br>
<br>&nbsp;&nbsp;private&nbsp;$journal=null;
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;getJournal(){return&nbsp;$this->journal;}
<br>&nbsp;&nbsp;//public&nbsp;function&nbsp;getType(){return&nbsp;$this->journal->getType();}
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;getJournalId(){return&nbsp;$this->journal->getId();}
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;getFund(){return&nbsp;$this->journal->getFund();}
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;getFundId(){return&nbsp;$this->journal->getFundId();}
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;getPeriod(){return&nbsp;$this->journal->getPeriod();}
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;getPeriodId(){return&nbsp;$this->journal->getPeriod()->getId();}
<br>
<br>
<br>&nbsp;&nbsp;//don't&nbsp;customize&nbsp;this&nbsp;exept&nbsp;where&nbsp;noted
<br>&nbsp;&nbsp;function&nbsp;__construct($string,&nbsp;$journal,&nbsp;$respcentercode)
<br>&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->string=$string;
<br>&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;//auxilliary&nbsp;data
<br>&nbsp;&nbsp;&nbsp;&nbsp;//customize&nbsp;this
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->journal=$journal;
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->respcentercode=$respcentercode;
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->validate();&nbsp;&nbsp;//validate&nbsp;aux&nbsp;data
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->fields=array_merge($this->requiredfields,$this->optionalfields);
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;//if&nbsp;empty&nbsp;data,&nbsp;quit&nbsp;gracefully&nbsp;(no&nbsp;errors&nbsp;on&nbsp;screen)
<br>&nbsp;&nbsp;&nbsp;&nbsp;if($string=="")return;
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->output=$this->parse($this->string);
<br>&nbsp;&nbsp;&nbsp;&nbsp;//if&nbsp;second&nbsp;row&nbsp;doesn't&nbsp;exist,&nbsp;quit&nbsp;gracefully
<br>&nbsp;&nbsp;&nbsp;&nbsp;if(!isset($this->output[0]))return;
<br>&nbsp;&nbsp;&nbsp;&nbsp;if(!isset($this->output[1]))return;
<br>&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;//extract&nbsp;fields
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->fieldcols=$this->extractfields();
<br>&nbsp;&nbsp;&nbsp;&nbsp;//validate&nbsp;required&nbsp;fields&nbsp;exist
<br>&nbsp;&nbsp;&nbsp;&nbsp;foreach($this->requiredfields&nbsp;as&nbsp;$fieldname)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($this->fieldcols[$fieldname]===null)$this->errors[]=$fieldname."&nbsp;column&nbsp;does&nbsp;not&nbsp;exist";
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;//custom&nbsp;validate&nbsp;required&nbsp;fields
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->fieldcols['particulars']===null&nbsp;and&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->fieldcols['payee']===null&nbsp;and&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->fieldcols['payeeparticulars']===null&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)$this->errors[]="Payee/Particulars/PayeeParticulars&nbsp;column&nbsp;does&nbsp;not&nbsp;exist";
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elseif(
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->fieldcols['payeeparticulars']!==null&nbsp;and&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->fieldcols['payee']!==null&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->errors[]="Payee&nbsp;&&nbsp;PayeeParticulars&nbsp;columns&nbsp;must&nbsp;not&nbsp;be&nbsp;both&nbsp;present";
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elseif(
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->fieldcols['payeeparticulars']!==null&nbsp;and&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->fieldcols['particulars']!==null&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->errors[]="Particulars&nbsp;&&nbsp;PayeeParticulars&nbsp;columns&nbsp;must&nbsp;not&nbsp;be&nbsp;both&nbsp;present";
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;//if&nbsp;required&nbsp;fields&nbsp;missing,&nbsp;quit
<br>&nbsp;&nbsp;&nbsp;&nbsp;if($this->hasErrors())return;
<br>&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->process();
<br>&nbsp;&nbsp;}
<br>&nbsp;&nbsp;//customize&nbsp;this
<br>&nbsp;&nbsp;private&nbsp;function&nbsp;process()
<br>&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->accountcodes=$this->extractaccountcodes();
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->processcompiledrows();
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->validateitems();
<br>&nbsp;&nbsp;}
<br>
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;getErrors(){return&nbsp;$this->errors;}
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;hasErrors(){return&nbsp;count($this->errors)>0;}
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;getMessages(){return&nbsp;$this->messages;}
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;getWarnings(){return&nbsp;$this->warnings;}
<br>
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;addError($msg){$this->errors[]=$msg;}
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;addWarning($msg){$this->warnings[]=$msg;}
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;addMessage($msg){$this->messages[]=$msg;}
<br>
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;getRequiredFields(){return&nbsp;$this->requiredfields;}
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;getOptionalFields(){return&nbsp;$this->optionalfields;}
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;getFields(){return&nbsp;$this->fields;}
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;getString(){return&nbsp;$this->string;}
<br>
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;getOutput(){return&nbsp;$this->output;}
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;getFieldCols(){return&nbsp;$this->fieldcols;}
<br>
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;getItems(){return&nbsp;$this->items;}
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;getItem($index){if(isset($this->items[$index]))return&nbsp;$this->items[$index];}
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;addItem($item){$this->items[]=$item;}
<br>
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;str_cleanup($string)
<br>&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;$string=str_replace("-","",$string);
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;//look&nbsp;for&nbsp;parentheses
<br>&nbsp;&nbsp;&nbsp;&nbsp;$start=strpos($string,"(");
<br>&nbsp;&nbsp;&nbsp;&nbsp;$end=strpos($string,")")+1;
<br>&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;//according&nbsp;to&nbsp;parentheses&nbsp;positions,&nbsp;remove&nbsp;letters&nbsp;in&nbsp;parentheses
<br>&nbsp;&nbsp;&nbsp;&nbsp;while($start!==false&nbsp;and&nbsp;$end!==false&nbsp;and&nbsp;$end-$start)
<br>&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//if&nbsp;parentheses&nbsp;surround&nbsp;entire&nbsp;string,&nbsp;extract&nbsp;entire&nbsp;string
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($start==0&nbsp;and&nbsp;$end==strlen($string))
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$string=substr($string,$start+1,$end-$start-2);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//else,&nbsp;remove&nbsp;string&nbsp;inside&nbsp;parentheses
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$extract=substr($string,$start,$end-$start);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$string=str_replace($extract,"",$string);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$start=strpos($string,"(");
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$end=strpos($string,")")+1;
<br>&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;$string;
<br>&nbsp;&nbsp;}
<br>&nbsp;&nbsp;//don't&nbsp;customize&nbsp;this
<br>&nbsp;&nbsp;private&nbsp;function&nbsp;parse()
<br>&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;$output=array();
<br>&nbsp;&nbsp;&nbsp;&nbsp;$rows=explode("\n",$this->string);
<br>&nbsp;&nbsp;&nbsp;&nbsp;foreach($rows&nbsp;as&nbsp;$row)
<br>&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$items=explode("\t",$row);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$array=array();
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach($items&nbsp;as&nbsp;$item)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$array[]=trim($item);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$output[]=$array;
<br>&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;$output;
<br>&nbsp;&nbsp;}
<br>&nbsp;&nbsp;//don't&nbsp;customize&nbsp;this
<br>&nbsp;&nbsp;private&nbsp;function&nbsp;processcompiledrows()
<br>&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;$item=null;&nbsp;//set&nbsp;of&nbsp;rows&nbsp;belonging&nbsp;to&nbsp;an&nbsp;item
<br>&nbsp;&nbsp;&nbsp;&nbsp;$start=false;&nbsp;//start&nbsp;of&nbsp;data&nbsp;rows&nbsp;has&nbsp;been&nbsp;encountered
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;//for&nbsp;each&nbsp;row&nbsp;in&nbsp;output&nbsp;except&nbsp;the&nbsp;first&nbsp;one
<br>&nbsp;&nbsp;&nbsp;&nbsp;foreach($this->output&nbsp;as&nbsp;$rowno=>$row)
<br>&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//skip&nbsp;first&nbsp;row
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($rowno==0)continue;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//if&nbsp;hasn't&nbsp;started&nbsp;data,&nbsp;and&nbsp;first&nbsp;column&nbsp;empty,&nbsp;skip&nbsp;this&nbsp;row
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//if&nbsp;hasn't&nbsp;started&nbsp;data,&nbsp;and&nbsp;first&nbsp;column&nbsp;full,&nbsp;go&nbsp;on
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!$row[0]&nbsp;and&nbsp;!$start)continue;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//first&nbsp;column&nbsp;of&nbsp;this&nbsp;row&nbsp;is&nbsp;not&nbsp;empty.&nbsp;start&nbsp;of&nbsp;data&nbsp;is&nbsp;encountered,&nbsp;here&nbsp;or&nbsp;previously.
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($row[0])
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$start=true;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//this&nbsp;is&nbsp;a&nbsp;new&nbsp;item.&nbsp;save&nbsp;the&nbsp;old&nbsp;item&nbsp;if&nbsp;it&nbsp;exists&nbsp;and&nbsp;create&nbsp;a&nbsp;new&nbsp;item.
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//if&nbsp;there&nbsp;is&nbsp;an&nbsp;old&nbsp;item
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($item)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//save&nbsp;the&nbsp;old&nbsp;item&nbsp;first
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//$this->items[]=$item;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->items[]=new&nbsp;TextInputItem($item['itemrows'],$this);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//initialize&nbsp;an&nbsp;item
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item=array();
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item['itemrows']=array();
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//save&nbsp;the&nbsp;current&nbsp;row&nbsp;in&nbsp;this&nbsp;item
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item['itemrows'][]=$row;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//if&nbsp;first&nbsp;column&nbsp;of&nbsp;this&nbsp;row&nbsp;is&nbsp;empty,&nbsp;but&nbsp;start=true,&nbsp;don't&nbsp;create&nbsp;a&nbsp;new&nbsp;item,&nbsp;just&nbsp;add&nbsp;this&nbsp;to&nbsp;the&nbsp;old&nbsp;item
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//save&nbsp;the&nbsp;current&nbsp;row&nbsp;in&nbsp;this&nbsp;item
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item['itemrows'][]=$row;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;//save&nbsp;last&nbsp;row&nbsp;into&nbsp;global&nbsp;array
<br>&nbsp;&nbsp;&nbsp;&nbsp;//$this->items[]=$item;
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->items[]=new&nbsp;TextInputItem($item['itemrows'],$this);
<br>&nbsp;&nbsp;}
<br>&nbsp;&nbsp;//customize&nbsp;this
<br>&nbsp;&nbsp;private&nbsp;function&nbsp;extractfields()
<br>&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;//OB.R.&nbsp;#	NAME	P&nbsp;A&nbsp;R&nbsp;T&nbsp;I&nbsp;C&nbsp;U&nbsp;L&nbsp;A&nbsp;R&nbsp;S	OFFICE	ACCT.&nbsp;CODE	AMOUNT
<br>&nbsp;&nbsp;&nbsp;&nbsp;$fieldcols=array();
<br>&nbsp;&nbsp;&nbsp;&nbsp;foreach($this->fields&nbsp;as&nbsp;$field)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$fieldcols[$field]=null;
<br>&nbsp;&nbsp;&nbsp;&nbsp;foreach($this->output[0]&nbsp;as&nbsp;$colno&nbsp;=>&nbsp;$field)
<br>&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch(strtolower($field))
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;'date':$fieldcols['date']=$colno;break;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;'ref':$fieldcols['ref']=$colno;break;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;'particulars':$fieldcols['particulars']=$colno;break;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;'code':
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;'jevno':
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$fieldcols['code']=$colno;break;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;'check':
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;'checkno':$fieldcols['checkno']=$colno;break;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;'payee':$fieldcols['payee']=$colno;break;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;'payeeparticulars':$fieldcols['payeeparticulars']=$colno;break;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;'sundry':$fieldcols['sundry']=$colno;break;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;'sundrydebit':$fieldcols['sundrydebit']=$colno;break;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;'sundrycredit':$fieldcols['sundrycredit']=$colno;break;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;'pr':$fieldcols['pr']=$colno;break;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;'voucher':
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;'dvno':$fieldcols['dvno']=$colno;break;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;'or':
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;'obrno':$fieldcols['obrno']=$colno;break;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;'pto':$fieldcols['pto']=$colno;break;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;$fieldcols;
<br>&nbsp;&nbsp;}
<br>&nbsp;&nbsp;//customize&nbsp;this
<br>&nbsp;&nbsp;private&nbsp;function&nbsp;validate()
<br>&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;//validate&nbsp;default&nbsp;resp&nbsp;center
<br>&nbsp;&nbsp;&nbsp;&nbsp;if($this->respcentercode)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!$this->validaterespcenter($this->respcentercode))
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->errors[]="Invalid&nbsp;Responsibility&nbsp;Center&nbsp;code:&nbsp;".$this->respcentercode;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;/*
<br>&nbsp;&nbsp;&nbsp;&nbsp;//validate&nbsp;fund&nbsp;id
<br>&nbsp;&nbsp;&nbsp;&nbsp;if($this->fund_id)
<br>&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!$this->fund=$this->validatefundid($this->fund_id))
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->errors[]="Invalid&nbsp;Fund&nbsp;Id:&nbsp;".$this->fund_id;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;else
<br>&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->errors[]="Fund&nbsp;Required";
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;
<br>&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;*/
<br>&nbsp;&nbsp;}
<br>&nbsp;&nbsp;private&nbsp;function&nbsp;validateitems()
<br>&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;$codelist=array();
<br>&nbsp;&nbsp;&nbsp;&nbsp;foreach($this->items&nbsp;as&nbsp;$index=>$item)
<br>&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$data=$item->getData();
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//validate&nbsp;jev&nbsp;code&nbsp;is&nbsp;not&nbsp;in&nbsp;other&nbsp;records
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(array_search($data['code'],$codelist)!==false)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$error="JEV&nbsp;".$data['code']."&nbsp;is&nbsp;used&nbsp;more&nbsp;than&nbsp;once";
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item->addError($error);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->errors[]=$error;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$codelist[$data['code']]=$data['code'];
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;}
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;//validate&nbsp;jev&nbsp;code&nbsp;is&nbsp;not&nbsp;in&nbsp;database
<br>&nbsp;&nbsp;&nbsp;&nbsp;foreach($codelist&nbsp;as&nbsp;$code)
<br>&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($code)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$j=Doctrine::getTable('JournalEntry')->findOneByCode($code);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($j)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$error="JEV&nbsp;".$code."&nbsp;already&nbsp;exists&nbsp;in&nbsp;the&nbsp;database";
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item->addError($error);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->errors[]=$error;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$error="JEV&nbsp;No.&nbsp;cannot&nbsp;be&nbsp;empty";
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item->addError($error);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->errors[]=$error;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;}
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;validaterespcenter($respcentercode)
<br>&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;if($respcentercode)
<br>&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$RespCenter=Doctrine::getTable('RespCenter')->findOneByCode($respcentercode);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!$RespCenter)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;false;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;true;
<br>&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;true;
<br>&nbsp;&nbsp;}
<br>&nbsp;&nbsp;/*
<br>&nbsp;&nbsp;private&nbsp;function&nbsp;validatefundid($fund_id)
<br>&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;$fund=Doctrine::getTable('Fund')->find(array($fund_id));
<br>&nbsp;&nbsp;&nbsp;&nbsp;if(!$fund)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;false;
<br>&nbsp;&nbsp;&nbsp;&nbsp;else
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;$fund;
<br>&nbsp;&nbsp;}
<br>&nbsp;&nbsp;*/
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;generate()
<br>&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;foreach($this->items&nbsp;as&nbsp;$item)
<br>&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$conn&nbsp;=&nbsp;Doctrine::getTable('JournalEntry')->getConnection();
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$conn->beginTransaction();
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item->generate($conn);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$conn->commit();
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;catch&nbsp;(Exception&nbsp;$e)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$conn->rollBack();
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->errors[]="Error&nbsp;creating&nbsp;JEV&nbsp;".$this->data['code'].":&nbsp;Please&nbsp;contact&nbsp;the&nbsp;programmer";
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;$e;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;}
<br>&nbsp;&nbsp;//this&nbsp;is&nbsp;a&nbsp;custom&nbsp;function
<br>&nbsp;&nbsp;private&nbsp;function&nbsp;extractaccountcodes()
<br>&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;//first&nbsp;row&nbsp;contains&nbsp;fields
<br>&nbsp;&nbsp;&nbsp;&nbsp;$fieldsrow=$this->output[0];&nbsp;
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;//second&nbsp;row&nbsp;contains&nbsp;account&nbsp;codes
<br>&nbsp;&nbsp;&nbsp;&nbsp;$accountcodesrow=$this->output[1];&nbsp;
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;$accountcodes=array();
<br>&nbsp;&nbsp;&nbsp;&nbsp;foreach($accountcodesrow&nbsp;as&nbsp;$colno&nbsp;=>&nbsp;$accountcode)
<br>&nbsp;&nbsp;&nbsp;&nbsp;if($accountcode)
<br>&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$subcode=$accountcode;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$array=explode("-",$accountcode);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$accountcode=$array[0];
<br>&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$account=Doctrine::getTable('Account')->findOneByCode($accountcode);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//validate&nbsp;account&nbsp;exists
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!$account)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->errors[]="Invalid&nbsp;Account&nbsp;code:&nbsp;".$accountcode;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$array=array();
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$array['col']=$colno;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$array['code']=$accountcode;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$array['account']=$account;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$array['subcode']=$subcode;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$array['debitcredit']=strtolower($fieldsrow[$colno]);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($array['debitcredit']!='debit'&nbsp;and&nbsp;$array['debitcredit']!='credit')
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->errors[]="Account&nbsp;code&nbsp;".$array['code']."&nbsp;must&nbsp;have&nbsp;'debit'&nbsp;or&nbsp;'credit'&nbsp;written&nbsp;above&nbsp;it&nbsp;(Please&nbsp;check&nbsp;the&nbsp;spelling.&nbsp;Capitalization&nbsp;not&nbsp;important.)";
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//check&nbsp;if&nbsp;separate&nbsp;subcode&nbsp;column&nbsp;exists
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$array['subcodecol']=null;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(isset($fieldsrow[$colno+1])&nbsp;and&nbsp;strtolower($fieldsrow[$colno+1])=='subcode')
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$array['subcodecol']=$colno+1;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$accountcodes[]=$array;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;$accountcodes;
<br>&nbsp;&nbsp;}
<br>}
<br>//-------------------------------------------------------------------------------------------------------------------
<br>class&nbsp;TextInputItem
<br>{
<br>&nbsp;&nbsp;private&nbsp;$itemrows=array();
<br>&nbsp;&nbsp;private&nbsp;$compiledrow=array();
<br>&nbsp;&nbsp;private&nbsp;$itemcols=array();
<br>&nbsp;&nbsp;private&nbsp;$errors=array();
<br>&nbsp;&nbsp;private&nbsp;$messages=array();
<br>&nbsp;&nbsp;private&nbsp;$warnings=array();
<br>&nbsp;&nbsp;private&nbsp;$details=array();
<br>&nbsp;&nbsp;private&nbsp;$data=array();
<br>&nbsp;&nbsp;private&nbsp;$tie=null;&nbsp;&nbsp;//text&nbsp;input&nbsp;engine
<br>&nbsp;&nbsp;//don't&nbsp;customize&nbsp;this
<br>&nbsp;&nbsp;function&nbsp;__construct($itemrows,$tie)
<br>&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->tie=$tie;
<br>&nbsp;&nbsp;&nbsp;&nbsp;$fields=$this->tie->getFields();
<br>&nbsp;&nbsp;&nbsp;&nbsp;$fieldcols=$this->tie->getFieldCols();
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->itemrows=$itemrows;
<br>&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;$compiledrow=array();
<br>&nbsp;&nbsp;&nbsp;&nbsp;$itemcols=array();
<br>&nbsp;&nbsp;&nbsp;&nbsp;foreach($this->itemrows&nbsp;as&nbsp;$row)
<br>&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//save&nbsp;row&nbsp;to&nbsp;compiledrow&nbsp;and&nbsp;itemcols
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//for&nbsp;each&nbsp;cell&nbsp;in&nbsp;the&nbsp;row
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach($row&nbsp;as&nbsp;$colno=>$cell)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//create&nbsp;compiledrow&nbsp;cell&nbsp;if&nbsp;it&nbsp;does&nbsp;not&nbsp;exist
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!isset($compiledrow[$colno]))$compiledrow[$colno]="";
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//add&nbsp;cell&nbsp;contents&nbsp;to&nbsp;compiledrow&nbsp;cell&nbsp;(cell&nbsp;contents&nbsp;have&nbsp;been&nbsp;previously&nbsp;trimmed)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$compiledrow[$colno]=trim($compiledrow[$colno]."&nbsp;".$cell);
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//add&nbsp;it&nbsp;as&nbsp;an&nbsp;array
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$itemcols[$colno][]=$cell;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->compiledrow=$compiledrow;
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->itemcols=$itemcols;
<br>&nbsp;&nbsp;&nbsp;&nbsp;foreach($fields&nbsp;as&nbsp;$fieldname)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->data[$fieldname]=$fieldcols[$fieldname]!==null?$compiledrow[$fieldcols[$fieldname]]:"";
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->preprocess($fieldcols);
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->validate();
<br>&nbsp;&nbsp;}
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;getData(){return&nbsp;$this->data;}
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;getDetails(){return&nbsp;$this->details;}
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;getErrors(){return&nbsp;$this->errors;}
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;getWarnings(){return&nbsp;$this->warnings;}
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;getMessages(){return&nbsp;$this->messages;}
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;getItemCols(){return&nbsp;$this->itemcols;}
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;getItemRows(){return&nbsp;$this->itemrows;}
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;getCompiledRow(){return&nbsp;$this->compiledrow;}
<br>
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;addError($msg){$this->errors[]=$msg;}
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;addWarning($msg){$this->warnings[]=$msg;}
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;addMessage($msg){$this->messages[]=$msg;}
<br>
<br>&nbsp;&nbsp;//customize&nbsp;this
<br>&nbsp;&nbsp;public&nbsp;function&nbsp;generate($conn)
<br>&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;$jentry=$this->data;
<br>&nbsp;&nbsp;&nbsp;&nbsp;$journal_entry=new&nbsp;JournalEntry();
<br>&nbsp;&nbsp;&nbsp;&nbsp;$journal_entry->setCode($jentry['code']);
<br>&nbsp;&nbsp;&nbsp;&nbsp;$journal_entry->setDate($jentry['date']);
<br>&nbsp;&nbsp;&nbsp;&nbsp;$journal_entry->setDescription($jentry['description']);
<br>&nbsp;&nbsp;&nbsp;&nbsp;$journal_entry->setRef($jentry['ref']);
<br>&nbsp;&nbsp;&nbsp;&nbsp;$journal_entry->setPeriodId($this->tie->getPeriodId());
<br>&nbsp;&nbsp;&nbsp;&nbsp;$journal_entry->setFundId($this->tie->getFundId());
<br>&nbsp;&nbsp;&nbsp;&nbsp;$journal_entry->setJournalId($this->tie->getJournalId());
<br>&nbsp;&nbsp;&nbsp;&nbsp;$journal_entry->setRespCenterCode($jentry['respcentercode']);&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;$journal_entry->setObrno($jentry['obrno']);&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;$journal_entry->setDvno($jentry['dvno']);&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;$journal_entry->setPtono($jentry['pto']);&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;$journal_entry->setCheckno($jentry['checkno']);&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;$journal_entry->setPayee($jentry['payee']);&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;$journal_entry->setIsEmpty(false);
<br>&nbsp;&nbsp;&nbsp;&nbsp;if($jentry['respcentercode']=='forward')$journal_entry->setIsBalanceForwarded(true);
<br>&nbsp;&nbsp;&nbsp;&nbsp;$journal_entry->save($conn);
<br>&nbsp;&nbsp;&nbsp;&nbsp;foreach($this->details&nbsp;as&nbsp;$accentry)
<br>&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$account_entry=new&nbsp;AccountEntry();
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$account_entry->setJournalEntryId($journal_entry->getId());
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$account_entry->setPeriodId($this->tie->getPeriodId());
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($accentry['debitcredit']=='debit')
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$account_entry->setDebit($accentry['amount']+0);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$account_entry->setCredit(0);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$account_entry->setCredit($accentry['amount']+0);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$account_entry->setDebit(0);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$account_entry->setAccountCode($accentry['acctcode']);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$account_entry->setSubsidiaryCode($accentry['subcode']);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$account_entry->setPurchaseRequestCode($accentry['prcode']);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$account_entry->setFundId($this->tie->getFundId());
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$account_entry->save($conn);
<br>&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->tie->addMessage("JEV-".$this->data['code']."&nbsp;successfully&nbsp;saved&nbsp;to&nbsp;database");
<br>&nbsp;&nbsp;}
<br>&nbsp;&nbsp;//customize&nbsp;this
<br>&nbsp;&nbsp;private&nbsp;function&nbsp;preprocess($fieldcols)
<br>&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;$jentry=$this->data;&nbsp;&nbsp;//nickname
<br>&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;//-----------code------------------------------------------
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;//set&nbsp;as&nbsp;code&nbsp;of&nbsp;first&nbsp;row
<br>&nbsp;&nbsp;&nbsp;&nbsp;$jentry['code']=$this->itemrows[0][$fieldcols['code']];
<br>&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;//if&nbsp;it&nbsp;ends&nbsp;in&nbsp;a&nbsp;'-',&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;if($jentry['code'][strlen($jentry['code'])-1]=="-")
<br>&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//append&nbsp;the&nbsp;one&nbsp;in&nbsp;the&nbsp;row&nbsp;below&nbsp;it
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$jentry['code'].=$this->itemrows[1][$fieldcols['code']];
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->itemrows[1][$fieldcols['code']]="";
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->itemcols[$fieldcols['code']][1]="";
<br>&nbsp;&nbsp;&nbsp;&nbsp;}
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;//if&nbsp;4&nbsp;or&nbsp;more&nbsp;parts,&nbsp;first&nbsp;part&nbsp;is&nbsp;the&nbsp;resp&nbsp;center
<br>&nbsp;&nbsp;&nbsp;&nbsp;$jevnoarray=explode("-",$jentry['code']);
<br>&nbsp;&nbsp;&nbsp;&nbsp;if(count($jevnoarray)>=4)
<br>&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$jentry['respcentercode']=$jevnoarray[0];
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unset($jevnoarray[0]);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$jentry['code']=implode("-",$jevnoarray);
<br>&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;else
<br>&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$jentry['respcentercode']=($this->tie->getRespCenterCode())?$this->tie->getRespCenterCode():"-";
<br>&nbsp;&nbsp;&nbsp;&nbsp;}
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;//processing&nbsp;for&nbsp;'code':&nbsp;remove&nbsp;empty&nbsp;spaces
<br>&nbsp;&nbsp;&nbsp;&nbsp;$jentry['code']=str_replace('&nbsp;','',$jentry['code']);
<br>&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;$count=0;
<br>&nbsp;&nbsp;&nbsp;&nbsp;foreach($this->itemcols[$fieldcols['code']]&nbsp;as&nbsp;$row)
<br>&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($row)$count++;
<br>&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;if($count>1)
<br>&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$error="JEV&nbsp;".$jentry['code'].":&nbsp;multiple&nbsp;jev&nbsp;nos.";
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->addError($error);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->tie->addError($error);
<br>&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;//-----------dvno&nbsp;if&nbsp;it&nbsp;exists
<br>&nbsp;&nbsp;&nbsp;&nbsp;if($jentry['dvno'])
<br>&nbsp;&nbsp;&nbsp;&nbsp;//if&nbsp;it&nbsp;ends&nbsp;in&nbsp;a&nbsp;'-',&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;if($jentry['dvno'][strlen($jentry['dvno'])-1]=="-")
<br>&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//append&nbsp;the&nbsp;one&nbsp;in&nbsp;the&nbsp;row&nbsp;below&nbsp;it
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$jentry['dvno'].=$this->itemrows[1][$fieldcols['dvno']];
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->itemrows[1][$fieldcols['dvno']]="";
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->itemcols[$fieldcols['dvno']][1]="";
<br>&nbsp;&nbsp;&nbsp;&nbsp;}
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;//-----------payee&nbsp;/&nbsp;particulars&nbsp;/&nbsp;payeeparticulars---------------------------------------
<br>&nbsp;&nbsp;&nbsp;&nbsp;//chop&nbsp;up&nbsp;payeeparticulars&nbsp;into&nbsp;payee&nbsp;&&nbsp;particulars
<br>&nbsp;&nbsp;&nbsp;&nbsp;if($jentry['payeeparticulars'])
<br>&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$pparray=$this->itemcols[$fieldcols['payeeparticulars']];
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$pparray1=explode("-",$pparray[0]);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$jentry['payee']=$pparray1[0];
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unset($pparray1[0]);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$pp1remainder=implode("-",$pparray1);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unset($pparray[0]);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$ppremainder=implode("\n",$pparray);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$jentry['particulars']=$pp1remainder."&nbsp;".$ppremainder;
<br>&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;//-----------description---------------------------------------
<br>&nbsp;&nbsp;&nbsp;&nbsp;//hmmm,&nbsp;maybe&nbsp;not
<br>&nbsp;&nbsp;&nbsp;&nbsp;$jentry['description']=$jentry['particulars'];
<br>&nbsp;&nbsp;&nbsp;&nbsp;/*
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.($jentry['payee']?";&nbsp;Payee:&nbsp;".$jentry['payee']:"")
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.($jentry['checkno']?";&nbsp;Check&nbsp;no.&nbsp;".$jentry['checkno']:"")
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.($jentry['pto']?";&nbsp;PTO#".$jentry['pto']:"")
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.($jentry['dvno']?";&nbsp;DV#".$jentry['dvno']:"")
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.($jentry['obrno']?";&nbsp;OR#".$jentry['obrno']:"")
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;
<br>&nbsp;&nbsp;&nbsp;&nbsp;*/
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;//-----------detail-------------------------------
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->details=array_merge($this->processaccentries($this->itemrows),$this->processsundry($this->itemrows));
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;//-----------done-------------------------------
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->data=$jentry;
<br>&nbsp;&nbsp;}
<br>&nbsp;&nbsp;private&nbsp;function&nbsp;processsundry($itemrows)
<br>&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;$fieldcols=$this->tie->getFieldCols();
<br>&nbsp;&nbsp;&nbsp;&nbsp;$accentries=array();
<br>&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;foreach($itemrows&nbsp;as&nbsp;$row)
<br>&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//for&nbsp;each&nbsp;entry&nbsp;in&nbsp;sundry&nbsp;column&nbsp;($fieldcols['sundry'])
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$sundryaccount=isset($row[$fieldcols['sundry']])?$row[$fieldcols['sundry']]:"";
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$sundrydebit=isset($row[$fieldcols['sundrydebit']])?$row[$fieldcols['sundrydebit']]:"";
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$sundrycredit=isset($row[$fieldcols['sundrycredit']])?$row[$fieldcols['sundrycredit']]:"";
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$pr=isset($row[$fieldcols['pr']])?$row[$fieldcols['pr']]:"";
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//ignore&nbsp;empty&nbsp;strings
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!$sundryaccount)continue;
<br>&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//validate&nbsp;account&nbsp;code&nbsp;exists,&nbsp;format&nbsp;it
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$subcode=$sundryaccount;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$accountarray=explode("-",$sundryaccount);&nbsp;//[0]=account&nbsp;code,&nbsp;[1]=subsidiary&nbsp;code,&nbsp;if&nbsp;it&nbsp;exists
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$accountcode=$accountarray[0];
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//if&nbsp;subcode&nbsp;is&nbsp;set
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(isset($accountarray[1]))
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//validate&nbsp;subcode
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$subsidiary=Doctrine::getTable('Subsidiary')->findOneByCode($subcode);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!$subsidiary)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$error="JEV&nbsp;".$this->data['code'].":&nbsp;Subsidiary&nbsp;Account&nbsp;with&nbsp;code&nbsp;".$subcode."&nbsp;does&nbsp;not&nbsp;exists&nbsp;in&nbsp;the&nbsp;database.";
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->errors[]=$error;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->tie->addError($error);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//validate&nbsp;account&nbsp;code
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$account=Doctrine::getTable('Account')->findOneByCode($accountcode);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!$account)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$error="JEV&nbsp;".$this->data['code'].":&nbsp;Account&nbsp;with&nbsp;code&nbsp;".$accountcode."&nbsp;does&nbsp;not&nbsp;exists&nbsp;in&nbsp;the&nbsp;database.";
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->errors[]=$error;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->tie->addError($error);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//validate&nbsp;account&nbsp;code
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$account=Doctrine::getTable('Account')->findOneByCode($accountcode);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!$account)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$error="JEV&nbsp;".$this->data['code'].":&nbsp;Account&nbsp;with&nbsp;code&nbsp;".$accountcode."&nbsp;does&nbsp;not&nbsp;exists&nbsp;in&nbsp;the&nbsp;database.";
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->errors[]=$error;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->tie->addError($error);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//else
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//process&nbsp;amount&nbsp;data
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$amount=0;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$type="";
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($sundrydebit>0)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$amount=$sundrydebit;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$type='debit';
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elseif($sundrycredit>0)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$amount=$sundrycredit;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$type='credit';
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$acctcode=array();
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$acctcode['code']=$accountcode;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$acctcode['subcode']=$subcode;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$acctcode['account']=$account;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$acctcode['debitcredit']=$type;
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//if&nbsp;there's&nbsp;an&nbsp;amount&nbsp;in&nbsp;the&nbsp;account's&nbsp;column,&nbsp;create&nbsp;account&nbsp;entry
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($amount)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$accentry=array();
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$accentry['acctcode']=$acctcode['code'];
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$accentry['subcode']=$acctcode['subcode'];
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$accentry['account']=$acctcode['account'];
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$accentry['prcode']=isset($prs)?$prs[$index]:"";
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$accentry['amount']=$amount;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$accentry['debitcredit']=$acctcode['debitcredit'];
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//format&nbsp;amount
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$accentry['amount']=str_replace(",","",$accentry['amount']);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$accentries[]=$accentry;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;}
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;$accentries;
<br>&nbsp;&nbsp;}
<br>&nbsp;&nbsp;private&nbsp;function&nbsp;processaccentries($itemrows)
<br>&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;$accentries=array();
<br>&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;foreach($itemrows&nbsp;as&nbsp;$row)
<br>&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//go&nbsp;through&nbsp;each&nbsp;account&nbsp;code&nbsp;in&nbsp;acctcode
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach($this->tie->getAccountCodes()&nbsp;as&nbsp;$acctcode)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//if&nbsp;there's&nbsp;an&nbsp;amount&nbsp;in&nbsp;the&nbsp;accounts&nbsp;column,&nbsp;create&nbsp;account&nbsp;entry
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$amount=0;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//fetch&nbsp;amount
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(isset($row[$acctcode['col']])&nbsp;and&nbsp;$row[$acctcode['col']]!="")
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$amount=$row[$acctcode['col']];
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//if&nbsp;there's&nbsp;an&nbsp;amount
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($amount)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$accentry=array();
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$accentry['acctcode']=$acctcode['code'];
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$accentry['subcode']=$acctcode['subcode'];
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//if&nbsp;there's&nbsp;a&nbsp;subcode&nbsp;column,&nbsp;check&nbsp;it&nbsp;out
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($acctcode['subcodecol']!==null)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$accentry['subcode']=$accentry['acctcode']."-".$this->tie->str_cleanup($row[$acctcode['subcodecol']]);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//special&nbsp;processing&nbsp;for&nbsp;subcode&nbsp;111&nbsp;-&nbsp;by&nbsp;journal&nbsp;current&nbsp;acct&nbsp;no.
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($accentry['subcode']=="111")
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch($this->tie->getJournal()->getAccountno())
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;"0732-1000-16":&nbsp;$accentry['subcode']="111-01";break;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;"0732-1073-39":&nbsp;$accentry['subcode']="111-02";break;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;"0732-1033-17":&nbsp;$accentry['subcode']="111-03";break;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;"0732-1073-63":&nbsp;$accentry['subcode']="111-04";break;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;"0732-1069-95":&nbsp;$accentry['subcode']="111-05";break;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$accentry['account']=$acctcode['account'];
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$accentry['prcode']="";
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$accentry['amount']=$row[$acctcode['col']];
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$accentry['debitcredit']=$acctcode['debitcredit'];
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//format&nbsp;amount
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$accentry['amount']=str_replace(",","",$accentry['amount']);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$accentries[]=$accentry;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;$accentries;
<br>&nbsp;&nbsp;}
<br>&nbsp;&nbsp;private&nbsp;function&nbsp;validate()
<br>&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;$jentry=$this->data;
<br>&nbsp;&nbsp;&nbsp;&nbsp;$errors=array();
<br>&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;//validate&nbsp;respcentercode&nbsp;data
<br>&nbsp;&nbsp;&nbsp;&nbsp;$respcentercode=$jentry['respcentercode'];
<br>&nbsp;&nbsp;&nbsp;&nbsp;if($respcentercode)
<br>&nbsp;&nbsp;&nbsp;&nbsp;foreach(explode("&nbsp;",$respcentercode)&nbsp;as&nbsp;$code)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!$this->tie->validaterespcenter($code))
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$errors[]="JEV&nbsp;".$jentry['code'].":&nbsp;Invalid&nbsp;Respcenter:&nbsp;".$code;
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;//validate&nbsp;>0&nbsp;accentries
<br>&nbsp;&nbsp;&nbsp;&nbsp;if(count($this->details)==0)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$errors[]="JEV&nbsp;".$jentry['code'].":&nbsp;No&nbsp;account&nbsp;entries";
<br>&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;//validate&nbsp;accentries&nbsp;balanced
<br>&nbsp;&nbsp;&nbsp;&nbsp;$totaldebit=0.00;
<br>&nbsp;&nbsp;&nbsp;&nbsp;$totalcredit=0.00;
<br>&nbsp;&nbsp;&nbsp;&nbsp;foreach($this->details&nbsp;as&nbsp;$index=>$accentry)
<br>&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($accentry['debitcredit']=='debit')
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$totaldebit+=$accentry['amount'];
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elseif($accentry['debitcredit']=='credit')
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$totalcredit+=$accentry['amount'];
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//validate&nbsp;amount&nbsp;is&nbsp;not&nbsp;0
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($accentry['amount']==0)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$errors[]="JEV&nbsp;".$jentry['code'].":&nbsp;Account&nbsp;entry&nbsp;amount&nbsp;cannot&nbsp;be&nbsp;0";
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//*
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//validate&nbsp;subsidiary&nbsp;code
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$subsidiary=SubsidiaryTable::getByCodeFund($accentry['subcode'],$this->tie->getFund());&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//if&nbsp;this&nbsp;subsidiary&nbsp;code&nbsp;is&nbsp;an&nbsp;account&nbsp;code&nbsp;without&nbsp;a&nbsp;subsidiary&nbsp;code
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!$subsidiary&nbsp;and&nbsp;count(explode("-",$accentry['subcode']))==1)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//generate&nbsp;subsidiary
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->details[$index]['subsidiary']=SubsidiaryTable::generate($accentry['subcode'],$accentry['account'],$this->tie->getFund());
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elseif(!$subsidiary)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$errors[]="JEV&nbsp;".$jentry['code'].":&nbsp;Invalid&nbsp;Subsidiary&nbsp;code:&nbsp;".$accentry['subcode'];
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->details[$index]['subsidiary']=$subsidiary;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//*/
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;//validate&nbsp;accentries&nbsp;balanced
<br>&nbsp;&nbsp;&nbsp;&nbsp;if(round($totaldebit,2)!=round($totalcredit,2))
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$errors[]="JEV&nbsp;".$jentry['code'].":&nbsp;Account&nbsp;entries&nbsp;not&nbsp;balanced";
<br>&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;//format&nbsp;and&nbsp;validate&nbsp;date
<br>&nbsp;&nbsp;&nbsp;&nbsp;$jentry['date']=str_replace("/","-",$jentry['date']);
<br>&nbsp;&nbsp;&nbsp;&nbsp;$datearray=explode('-',$jentry['date']);
<br>&nbsp;&nbsp;&nbsp;&nbsp;$jentry['date']=$datearray[2]."-".$datearray[0]."-".$datearray[1];
<br>&nbsp;&nbsp;&nbsp;&nbsp;$jentry['date']=MyDateTime::fromdate($jentry['date'])->todate();
<br>&nbsp;&nbsp;&nbsp;&nbsp;if($jentry['date']=='1970-01-01')
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$errors[]="JEV&nbsp;".$jentry['code'].":&nbsp;Invalid&nbsp;Date";
<br>&nbsp;&nbsp;&nbsp;&nbsp;else
<br>&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//if&nbsp;date&nbsp;does&nbsp;not&nbsp;fit&nbsp;period,&nbsp;write&nbsp;actual&nbsp;date&nbsp;in&nbsp;description,&nbsp;and&nbsp;give&nbsp;a&nbsp;fitting&nbsp;date
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$period=$this->tie->getPeriod();
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$startdate=MyDateTime::frommysql($period->getStartdate());
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$enddate=MyDateTime::frommysql($period->getEnddate());
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$date=MyDateTime::frommysql($jentry['date']);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($date->isbefore($startdate))
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$jentry['description'].=";&nbsp;Actual&nbsp;date:&nbsp;".$jentry['date'];
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$jentry['date']=$period->getStartdate();
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elseif($date->isafter($enddate))
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$jentry['description'].=";&nbsp;Actual&nbsp;date:&nbsp;".$jentry['date'];
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$jentry['date']=$period->getEnddate();
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;}
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;foreach($errors&nbsp;as&nbsp;$error)
<br>&nbsp;&nbsp;&nbsp;&nbsp;{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->addError($error);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->tie->addError($error);
<br>&nbsp;&nbsp;&nbsp;&nbsp;}
<br>&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;$this->data=$jentry;
<br>
<br>&nbsp;&nbsp;}
<br>}
<br>?><br>
<br>
<br><hr>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>

